<?php
namespace app\api\controller;

class Feedback 
{
    public function info()
    {
        $request = request();
        if ($request->isGet()) {
            $data = [
                'hotLine' => '400-666666',
                'orgs'    => [
                    ['orgCode'=>'o1', 'orgName'=>'机构一'],
                    ['orgCode'=>'o2', 'orgName'=>'机构二'],
                ],
                'complaints' => [
                    ['typeId'=>1, 'typeName'=>'投诉类型一'],
                    ['typeId'=>2, 'typeName'=>'投诉类型二'],
                ]
            ];
            return api_response(['get'], [], $data);
        }
        if ($request->isPost()) { // 提交表单
            $fields = ['orgCode', 'typeId', 'name', 'phone', 'content'];
            $errorInfo = '';
            foreach ($fields as $v) {
                if (! isset($_POST[$v])) {
                    $errorInfo = $v. ' 不存在';break;
                }
            }
            if ($errorInfo) {
                return error($errorInfo);
            } else {
                return success('提交成功');
            }
        }
    }

    public function history()
    {
        $field = ['token', 'limit', 'offset'];
        $data = [
            ['orgName'=>'机构名', 'typeName'=>'投诉类型一', 'content'=>'不开心不开心', 'createTime'=>'2017-07-12'],
            ['orgName'=>'机构名', 'typeName'=>'投诉类型一', 'content'=>'不开心不开心', 'createTime'=>'2017-07-12'],
            ['orgName'=>'机构名', 'typeName'=>'投诉类型一', 'content'=>'不开心不开心', 'createTime'=>'2017-07-12'],
            ['orgName'=>'机构名', 'typeName'=>'投诉类型一', 'content'=>'不开心不开心', 'createTime'=>'2017-07-12'],
        ];
        return api_response(['get','post'], [], $data, ['total'=>4]);
    }
}